package o;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Build.VERSION;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.bumptech.glide.Glide;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

@Deprecated
public class yp extends Fragment {
    @Nullable
    private Fragment ʼ;
    private final yr ˊ;
    @Nullable
    private rp ˋ;
    @Nullable
    private yp ˎ;
    private final yh ˏ;
    private final Set<yp> ॱ;

    class e implements yr {
        final /* synthetic */ yp ˎ;

        e(yp ypVar) {
            this.ˎ = ypVar;
        }

        @NonNull
        public Set<rp> ˋ() {
            Set<yp> ॱ = this.ˎ.ॱ();
            Set<rp> hashSet = new HashSet(ॱ.size());
            for (yp ypVar : ॱ) {
                if (ypVar.ˋ() != null) {
                    hashSet.add(ypVar.ˋ());
                }
            }
            return hashSet;
        }

        public String toString() {
            return super.toString() + "{fragment=" + this.ˎ + "}";
        }
    }

    public yp() {
        this(new yh());
    }

    @VisibleForTesting
    @SuppressLint({"ValidFragment"})
    yp(@NonNull yh yhVar) {
        this.ˊ = new e(this);
        this.ॱ = new HashSet();
        this.ˏ = yhVar;
    }

    public void ˋ(@Nullable rp rpVar) {
        this.ˋ = rpVar;
    }

    @NonNull
    yh ˏ() {
        return this.ˏ;
    }

    @Nullable
    public rp ˋ() {
        return this.ˋ;
    }

    @NonNull
    public yr ˊ() {
        return this.ˊ;
    }

    private void ˎ(yp ypVar) {
        this.ॱ.add(ypVar);
    }

    private void ॱ(yp ypVar) {
        this.ॱ.remove(ypVar);
    }

    @TargetApi(17)
    @NonNull
    Set<yp> ॱ() {
        if (equals(this.ˎ)) {
            return Collections.unmodifiableSet(this.ॱ);
        }
        if (this.ˎ == null || VERSION.SDK_INT < 17) {
            return Collections.emptySet();
        }
        Set hashSet = new HashSet();
        for (yp ypVar : this.ˎ.ॱ()) {
            if (ˎ(ypVar.getParentFragment())) {
                hashSet.add(ypVar);
            }
        }
        return Collections.unmodifiableSet(hashSet);
    }

    void ˋ(@Nullable Fragment fragment) {
        this.ʼ = fragment;
        if (fragment != null && fragment.getActivity() != null) {
            ˋ(fragment.getActivity());
        }
    }

    @TargetApi(17)
    @Nullable
    private Fragment ˎ() {
        Fragment parentFragment;
        if (VERSION.SDK_INT >= 17) {
            parentFragment = getParentFragment();
        } else {
            parentFragment = null;
        }
        return parentFragment != null ? parentFragment : this.ʼ;
    }

    @TargetApi(17)
    private boolean ˎ(@NonNull Fragment fragment) {
        Fragment parentFragment = getParentFragment();
        while (true) {
            Fragment parentFragment2 = fragment.getParentFragment();
            if (parentFragment2 == null) {
                return false;
            }
            if (parentFragment2.equals(parentFragment)) {
                return true;
            }
            fragment = fragment.getParentFragment();
        }
    }

    private void ˋ(@NonNull Activity activity) {
        ʽ();
        this.ˎ = Glide.ˎ((Context) activity).ʻ().ˋ(activity);
        if (!equals(this.ˎ)) {
            this.ˎ.ˎ(this);
        }
    }

    private void ʽ() {
        if (this.ˎ != null) {
            this.ˎ.ॱ(this);
            this.ˎ = null;
        }
    }

    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            ˋ(activity);
        } catch (Throwable e) {
            if (Log.isLoggable("RMFragment", 5)) {
                Log.w("RMFragment", "Unable to register fragment with root", e);
            }
        }
    }

    public void onDetach() {
        super.onDetach();
        ʽ();
    }

    public void onStart() {
        super.onStart();
        this.ˏ.ˎ();
    }

    public void onStop() {
        super.onStop();
        this.ˏ.ˏ();
    }

    public void onDestroy() {
        super.onDestroy();
        this.ˏ.ॱ();
        ʽ();
    }

    public String toString() {
        return super.toString() + "{parent=" + ˎ() + "}";
    }
}
